<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增兄弟楼宇')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-building-addBrothers" th:object="${building}">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">所属社区：</label>
                <div class="col-sm-8">
                    <input readonly="readonly" autocomplete="off" class="form-control" type="text" name="sqName"  id="sqName" th:field="*{sqName}" required>
                    <!--之所以不用hidden是因为hidden不能被表单的reset()方法清除值-->
                    <input type="text" style="display: none;" name="sqCode" id="sqCode" th:field="*{sqCode}" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">所属场所类型：</label>
                <div class="col-sm-8">
                    <input type="text" readonly="readonly"  class="form-control"
                           th:value="${@dict.getLabel('b_zzslx', building.sscsLx)}" />
                    <input type="text" style="display: none;" name="sscsLx" th:field="*{sscsLx}" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">所属场所名称：</label>
                <div class="col-sm-8">
                    <input readonly="readonly" name="sscsMc" th:field="*{sscsMc}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">楼号：</label>
                <div class="col-sm-8">
                    <input name="lh"  class="form-control" type="text"
                           required>
                </div>
            </div>
            <div class="form-group" style="display: none;">
                <label class="col-sm-3 control-label">每栋拥有单元数：</label>
                <div class="col-sm-8">
                    <input name="dys"  class="form-control" value="1" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">总层数：</label>
                <div class="col-sm-8">
                    <input name="cs" class="form-control" type="text"
                           min="0" max="254" digits="true" title="只能输入0-254之间的正整数" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">每层拥有户数：</label>
                <div class="col-sm-8">
                    <input name="hs" class="form-control" type="text"
                           min="0" max="254" digits="true" title="只能输入0-254之间的正整数" required>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "place/building";
        $("#form-building-addBrothers").validate({
            focusCleanup: true,
            rules:{
                lh:{
                    min:1,
                    max:254,
                    remote: {
                        url: prefix + "/checkunique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "lh": function() {
                                return $.common.trim($("input[name=lh]").val());
                            },
                            "sscsMc":function () {
                                return $.common.trim($("input[name=sscsMc]").val());
                            },
                            "sqCode":function () {
                                return $.common.trim($("input[name=sqCode]").val());
                            },
                            "sscsLx":function () {
                                return $.common.trim($("input[name=sscsLx]").val());
                            }
                        },
                        dataFilter: function(data, type) {
                            return $.validate.unique(data);
                        }
                    }
                }

            },
            messages:{
                lh:"只能输入1-254之间的正整数,且与现有楼号不能重复"
            }

        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-building-addBrothers').serialize());
            }
        }
    </script>
</body>
</html>